package com.bjtu.restaurantreviews.util;

import com.bjtu.restaurantreviews.domain.Result;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Author: Chen
 * @Description: 请求结果工具类
 * @Date: Created in 12:13 2018/4/4
 */

//请求成功，传入单个出参
public class ResultUtil {
    public static Result sucess(Object object){
        Result result = new Result();
        result.setSucess(true);
        result.setInfo("成功");
        result.setData(object);
        return result;
    }

    //提供不需要出参的接口
    public static Result sucess(){
        Result result = new Result();
        result.setSucess(true);
        result.setInfo("成功");
        result.setData("");
        return result;
    }
    //请求成功，传入多个出参
    public static Result sucess(ArrayList<Object> arrayList){
        Result<ArrayList<Object>> result = new Result();
        result.setSucess(true);
        result.setInfo("成功");
        result.setData(arrayList);
        return result;
    }

    //请求成功，传入多个出参(hashmap)
    public static Result sucess(HashMap<String,Object> hashMap){
        Result<HashMap<String,Object>> result = new Result();
        result.setSucess(true);
        result.setInfo("成功");
        result.setData(hashMap);
        return result;
    }

    //请求成功，传入多个出参(list)
    public static Result sucess(List<Object> list){
        Result<List<Object>> result = new Result();
        result.setSucess(true);
        result.setInfo("成功");
        result.setData(list);
        return result;
    }

    //请求失败，提供错误信息
    public static Result error(String info){
        Result result = new Result();
        result.setData(null);
        result.setInfo(info);
        result.setSucess(false);
        return result;
    }
}
